<template>
	<view class=""></view>
</template>
<script >
import { getAction } from '@/api/manage'
import { mapActions,mapMutations,mapGetters,mapState } from 'vuex'
import config from '@/config'
export default {
  async created() {
		try{
			if(this.token){
				this.toPage()
				return 
			}
			if(this.$store.state.user.loginNum >=2){
				this.$modal.msgError("登录失败，请重试")
				return 
			}
			uni.showLoading({
				 title: "加载中...",
				 mask: false
			});
			//系统自动登录
			await this.login();
			this.SET_LOGIN_NUM()
			uni.hideLoading();
		}catch(e){
			uni.hideLoading();
			//TODO handle the exception
			this.$modal.msgError("登录失败，请重试")
		}
  },
	computed:{
		...mapGetters(['token'])
	},
  methods: {
		...mapMutations(['SET_AUTH_CODE','SET_LOGIN_NUM']),
		async login(){
			this.$store.dispatch('Login', {
				username:'8888',
				password:'123456'
			}).then(res => {
				const data = res.data
				if(data.success){
					this.toPage()
				}else{
					this.$modal.msgError("登录失败，请重试")
				}
			})
		},
		toPage(){
			this.$tab.reLaunch(`/pages/index`)
		}
  }
}
</script>
<style lang="scss">
	page {
		background-color: #ffffff;
	}
</style>